package com.jmgd.cjlx.param.metuan;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.io.IOException;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MedicineResponse {
    private int code;
    private String msg;
    private Data data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Data getData() {
        return data;
    }

    public void setData(Data data) {
        this.data = data;
    }

    public static class Data {
        private List<Hit> hits;
        private int total;

        public List<Hit> getHits() {
            return hits;
        }

        public void setHits(List<Hit> hits) {
            this.hits = hits;
        }

        public int getTotal() {
            return total;
        }

        public void setTotal(int total) {
            this.total = total;
        }

        @JsonIgnoreProperties(ignoreUnknown = true)
        public static class Hit {
            @JsonProperty("app_medicine_code")
            private String appMedicineCode;

            @JsonProperty("category_code")
            private String categoryCode;

            @JsonProperty("category_name")
            private String categoryName;

            private long ctime;

            @JsonProperty("is_sold_out")
            private int isSoldOut;

            @JsonProperty("medicine_no")
            private String medicineNo;

            @JsonProperty("medicine_type")
            private int medicineType;

            private String name;
            private int sequence;

            private String skus; // Keep as a string
            @JsonProperty("tag_id")
            private int tagId;
            private long utime;

            @JsonDeserialize(using = LimitSaleInfoDeserializer.class)
            @JsonProperty("limit_sale_info")
            private LimitSaleInfo limitSaleInfo;

            public LimitSaleInfo getLimitSaleInfo() {
                return limitSaleInfo;
            }

            public void setLimitSaleInfo(LimitSaleInfo limitSaleInfo) {
                this.limitSaleInfo = limitSaleInfo;
            }

            public String getAppMedicineCode() {
                return appMedicineCode;
            }

            public void setAppMedicineCode(String appMedicineCode) {
                this.appMedicineCode = appMedicineCode;
            }

            public String getCategoryCode() {
                return categoryCode;
            }

            public void setCategoryCode(String categoryCode) {
                this.categoryCode = categoryCode;
            }

            public String getCategoryName() {
                return categoryName;
            }

            public void setCategoryName(String categoryName) {
                this.categoryName = categoryName;
            }

            public long getCtime() {
                return ctime;
            }

            public void setCtime(long ctime) {
                this.ctime = ctime;
            }

            public int getIsSoldOut() {
                return isSoldOut;
            }

            public void setIsSoldOut(int isSoldOut) {
                this.isSoldOut = isSoldOut;
            }

            public String getMedicineNo() {
                return medicineNo;
            }

            public void setMedicineNo(String medicineNo) {
                this.medicineNo = medicineNo;
            }

            public int getMedicineType() {
                return medicineType;
            }

            public void setMedicineType(int medicineType) {
                this.medicineType = medicineType;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public int getSequence() {
                return sequence;
            }

            public void setSequence(int sequence) {
                this.sequence = sequence;
            }

            public String getSkus() {
                return skus;
            }

            public void setSkus(String skus) {
                this.skus = skus;
            }

            public int getTagId() {
                return tagId;
            }

            public void setTagId(int tagId) {
                this.tagId = tagId;
            }

            public long getUtime() {
                return utime;
            }

            public void setUtime(long utime) {
                this.utime = utime;
            }

            public List<Sku> getSkusList() {
                ObjectMapper objectMapper = new ObjectMapper();
                try {
                    return objectMapper.readValue(skus, new TypeReference<List<Sku>>() {});
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }
    }
}

